package com.example.lin.config.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.context.annotation.Configuration;

import java.util.Date;

@Configuration
public class MyObjectHandler implements MetaObjectHandler {
    /**
     * 新增
     */
    @Override
    public void insertFill(MetaObject metaObject) {
        /**
         * 参数1：元数据对象
         * 参数2：属性名称
         * 参数3：类对象
         * 参数4：当前系统时间
         */
        this.strictInsertFill(metaObject, "createTime", Date.class, new Date());
        this.strictInsertFill(metaObject, "updateTime", Date.class, new Date());
    }

    /**
     * 修改
     */
    @Override
    public void updateFill(MetaObject metaObject) {
        this.strictInsertFill(metaObject, "updateTime", Date.class, new Date());
    }
}
